import api from './index.js'

export const syncAPI = {
  // 获取服务器数据
  async fetchServerData(since = null) {
    const params = since ? { since } : {}
    const [listsResponse, tasksResponse] = await Promise.all([
      api.get('/lists', { params }),
      api.get('/tasks', { params })
    ])
    
    return {
      lists: listsResponse.data.data,
      tasks: tasksResponse.data.data,
      timestamp: listsResponse.data.timestamp
    }
  },
  
  // 同步清单
  async syncLists(lists) {
    const response = await api.post('/lists/sync', { lists })
    return response.data
  },
  
  // 同步任务
  async syncTasks(tasks) {
    const response = await api.post('/tasks/sync', { tasks })
    return response.data
  },
  
  // 统一同步
  async syncAll(data) {
    const response = await api.post('/sync', data)
    return response.data
  },
  
  // 获取同步状态
  async getSyncStatus() {
    const response = await api.get('/sync/status')
    return response.data
  }
}